<%@ page import="java.util.HashMap, java.util.ArrayList"%>

<%@ page contentType="text/html;charset=windows-1252"%>
<script type="text/javascript" src="./vistas/pagina/js/funciones.js"></script>
<%
    boolean par = false;
    ArrayList<HashMap> carrito = new ArrayList<HashMap>();
    carrito =(ArrayList<HashMap>) session.getAttribute("carritosesion");
    String existe = (String)request.getAttribute("_existe");
    float total = 0;

    if(carrito == null){
        carrito = new ArrayList();
    }
    
%>
    
<script>
    function CalcularTotal(val){
        var nro = val;
        if(isNaN(nro)){
            alert("La cantidad debe ser numerica");
        }else{
            document.formCarrito.submit();
        }
    }
    function Eliminar(cod){
        var url = 'index?accion=carrito&'+
                        'carrito=eliminar'+
                        '&artEliminar=' + cod;
        document.location.replace(url);
    }
    function Confirmar(cli){
        if (cli != 'null'){
            var url = 'index?accion=confirmarcarrito';
            document.location.replace(url);
        }else{
            var url = 'index?accion=ingresarSesion';
            document.location.replace(url);
        }
    }
</script>
<div  align="center"><form action="index?accion=carrito&carrito=modificar" method="post" name="formCarrito" id="formCarrito">
        <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td class="hTituloContenidoHome"><div class="HTextoBlanc13PxCenter">MI CARRITO:</div> </td>
            </tr>
        </table>
        <table width="100%" cellpadding="0" cellspacing="0" >
            
            
            <tr width="100%" class="fondoTituloCarrito">
                <td>Cantidad</td>
                <td>C&oacute;digo</td>
                <td>Producto</td>
                <td>Precio Unitario</td>
                <td>Envio</td>
                <td>Total Compra</td>
                <td>Accion</td>
            </tr>

            <%
            for(HashMap item: carrito){
            if (!par){
            %>
            <tr class="fondoCaracteristicaImpar">
            <%
            par = true;
            }else{
            %>
            <tr class="fondoCaracteristicaPar">
                <%
                par = false;
                }//fin else
                %>
                <td><span class="textoCarrito">
                        <%if (item.get("cantidad")!=null){%>
                        <input name="cantidad_<%=item.get("artCodigo")%>" type="text" class="cantidadCarrito" value="<%=item.get("cantidad")%>" onchange="CalcularTotal(formCarrito.cantidad_<%=item.get("artCodigo")%>.value)">
                        <%}%>           
                </span></td>
                <td class="textoCarrito"><%=item.get("artCodigo")%></td>
                <td class="textoCarrito"><%=item.get("artNombre")%></td>
                <td class="textoCarrito">$<%=item.get("artPrecioDescuentoBruto")%></td>
                <td class="textoCarrito">$<%=item.get("artCostoEnvioBruto")%></td>
                <td class="textoCarrito">$<%=item.get("subTotal")%></td>
                <td class="accionArticulo"><a href="JavaScript:Eliminar('<%=item.get("artCodigo")%>')">Eliminar </a>  </td>
            </tr>
            <%
            if (!par){
            %>
            <tr class="fondoCaracteristicaPar">
            <%
            }else{
            %>
            <tr class="fondoCaracteristicaImpar">
            <%
            }//fin else
            %>
                <td colspan="7" height="6"></td>
            </tr>
            <%
                if (item.get("subTotal")!= null){
                    String subTotal = String.valueOf(item.get("subTotal"));
                    total = total + Float.parseFloat(subTotal);
                }//fin if
            }//fin for
            
            %>
            <tr class="fondoTituloCarrito">
                <td class="textoCarrito" colspan="4" height="20"> </td>
                <td class="textoCarrito" ><div align="right" height="20"><span class="fondoTituloCarrito">TOTAL:</span></div></td>
                <!--<td class="textoCarrito" height="20">$<%=total%></td>-->
                <td class="textoCarrito" height="20">$<%=total%></td>
                <td class="textoCarrito" height="20"> </td>
            </tr>
            
        </table>
    </form>
    <table width="100%" cellpadding="0" cellspacing="0">
        <tr class="separadorArticulo">
            <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <input name="Submit2" type="button" class="boton2" value="Seguir comprando" onclick="javascript:document.location.replace('index?accion=principal');"/>
                </div>
            </td>
            <td>
                <div align="center">
                    <input name="Submit22" type="button" class="boton2" value="Confirmar compra" onclick="Confirmar('<%=session.getAttribute("cliCodigo")%>')"/>
                </div>
            </td>
        </tr>
    </table>    
</div>
